package com.cosina.game.colorball;

import com.cosina.game.R;
import com.cosina.game.BallGameStartActivity;
import com.cosina.game.R.id;
import com.cosina.game.R.layout;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;

public class GameEndDialog {
	public static void show(final int score,final Context context) {
		final Difficulty difficulty = ((BallGameStartActivity) context).difficulty;
		boolean brokenRecord = Trophy.isBrokenRecord(score,difficulty);
		
		
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		if (brokenRecord) {
			builder.setTitle("new record " + score);
			View view = View.inflate(context, R.layout.newrecordinput, null);
			
			final EditText editText = (EditText)view.findViewById(R.id.recordowner);
			builder.setView(view);
			builder.setNeutralButton("Save",
					new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Trophy.saveBrokenRecord(score, editText.getText().toString(),difficulty);
						}
					});
		} else {
			builder.setTitle("Game over");
			builder.setMessage("you total score is " + score);
		}
		builder.setPositiveButton("New Game",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						((BallGameStartActivity) context).resetContent();

					}
				});
		builder.setNegativeButton("Exit",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						((BallGameStartActivity) context).finish();
					}
				});
		builder.create().show();
	}
}
